//
//  PGIndexBannerSubiew.m
//  NewPagedFlowViewDemo
//
//  Created by Mars on 16/6/18.
//  Copyright © 2016年 Mars. All rights reserved.
//  Designed By PageGuo,
//  QQ:799573715
//  github:https://github.com/PageGuo/NewPagedFlowView

#import "PGIndexBannerSubiew.h"

@implementation PGIndexBannerSubiew

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self addSubview:self.imgView];
        [self addSubview:self.indicateLabel];
//        [self addSubview:self.mainImageView];
        //      总列数
  
        
        
        
//        [self addSubview:self.coverView];
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleCellTapAction:)];
        [self addGestureRecognizer:singleTap];
    }
    
    return self;
}
- (void)setPicArr:(NSMutableArray *)picArr{
    
    UIImageView *bianKuangImgView = [[UIImageView alloc] init];
    [self addSubview:bianKuangImgView];
    bianKuangImgView.frame = CGRectMake(0, 30, screenScale(220), screenScale(350)-30);
    bianKuangImgView.image = [UIImage imageNamed:@"bg_7"];
    float Start_X = 9.0;// 第一个按钮的X坐标
    float Start_Y = 9.0;// 第一个按钮的Y坐标
    float Width_Space = 7;// 2个按钮之间的横间距
    float Height_Space = 7;// 竖间距
    float Button_Height = (screenScale(350)-66)/3;// 高
    float Button_Width = (screenScale(220) - 27) / 2;// 宽
    NSLog(@"44444444444444444444444%@", picArr);
    if (picArr.count > 6) {
        for (int i = 0 ; i < 6; i++) {
            NSInteger index2 = i % 2;
            NSInteger page = i / 2;
            
            // 圆角按钮
            UIImageView *aBt = [[UIImageView alloc] init];
            
            
            aBt.frame = CGRectMake(index2 * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
            aBt.backgroundColor = [UIColor whiteColor];
            [bianKuangImgView addSubview:aBt];
            [aBt sd_setImageWithURL:[picArr[i] objectForKey:@"img"] placeholderImage:[UIImage imageNamed:@""]];
            
        
            
        }
    }else{
        for (int i = 0 ; i < picArr.count; i++) {
            NSInteger index2 = i % 2;
            NSInteger page = i / 2;
            
            // 圆角按钮
            UIImageView *aBt = [[UIImageView alloc] init];
            
            
            aBt.frame = CGRectMake(index2 * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
            aBt.backgroundColor = [UIColor whiteColor];
            [bianKuangImgView addSubview:aBt];

            [aBt sd_setImageWithURL:[picArr[i] objectForKey:@"img"] placeholderImage:[UIImage imageNamed:@""]];
            
        }
    }
    
    
    
}
- (void)singleCellTapAction:(UIGestureRecognizer *)gesture {
    if (self.didSelectCellBlock) {
        self.didSelectCellBlock(self.tag, self);
    }
}

- (void)setSubviewsWithSuperViewBounds:(CGRect)superViewBounds {
    
    if (CGRectEqualToRect(self.mainImageView.frame, superViewBounds)) {
        return;
    }
    
//    self.mainImageView.frame = superViewBounds;
    self.mainImageView.frame = CGRectMake(0, 30, superViewBounds.size.width, superViewBounds.size.height-30);
//    self.coverView.frame = superViewBounds;
}

- (UIImageView *)mainImageView {
    
    if (_mainImageView == nil) {
        _mainImageView = [[UIImageView alloc] init];
        _mainImageView.userInteractionEnabled = YES;
    }
    return _mainImageView;
}

- (UIView *)coverView {
    if (_coverView == nil) {
        _coverView = [[UIView alloc] init];
        _coverView.backgroundColor = [UIColor blackColor];
    }
    return _coverView;
}
- (UILabel *)indicateLabel {
    
    if (_indicateLabel == nil) {
        UIImage *img = [UIImage imageNamed:@"line_1_b"];
        _indicateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,  0, img.size.width, 16)];
        _indicateLabel.textColor = [UIColor whiteColor];
        _indicateLabel.font = [UIFont systemFontOfSize:16.0];
        _indicateLabel.textAlignment = NSTextAlignmentCenter;
//        _indicateLabel.text = @"热门推荐";
    }
    
    return _indicateLabel;
}
- (UIImageView *)imgView{
    if (_imgView == nil) {
        UIImage *img = [UIImage imageNamed:@"line_1_b"];
        _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
        _imgView.image = [UIImage imageNamed:@"line_1_b"];
      
    }
    return _imgView;
    
}

//-(void)updateInfo:(NSArray*)SDCycleArr{
//    
//    _picArr=[[NSMutableArray alloc]init];
//    for (int i=0; i<SDCycleArr.count; i++) {
        
//        NSString *str=[SDCycleArr[i] objectForKey:@"pic"];
//        NSString *urlN=manage(AP_HOST, str);
        
//        [_picArr addObject:SDCycleArr[i]];
//    }
//
//}


@end
